package znbkTestPaperNtxl.presenter;

import android.util.Log;

import znbkListNtxl.ITrainingDifficultProblemsPresenter;
import com.example.lancooznbk.view.base.ILoadPaperView;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import znbkTestPaperNtxl.activity.TrainingDifficultProblemsPaperActivity;
import znbkTestPaperNtxl.entity.TrainingDifficultProblemsPaperEntity;
import znbkTestPaperNtxl.api.TrainingDifficultProblemsPaperApi;

/**
 * Created by Administrator on 2018\2\9 0009.
 */

public class TrainingDifficultProblemsPaperPresenter implements ITrainingDifficultProblemsPresenter {

    private ILoadPaperView view;

    public TrainingDifficultProblemsPaperPresenter(ILoadPaperView view) {
        this.view = (ILoadPaperView) view;
    }

    @Override
    public void getData(boolean isShowLoading) {
        if (isShowLoading) view.showLoading();

            HttpOnNextListener<TrainingDifficultProblemsPaperEntity> httpOnNextListener = new HttpOnNextListener<TrainingDifficultProblemsPaperEntity>() {
                @Override
                public void onNext(TrainingDifficultProblemsPaperEntity trainingDifficultProblemsPaperEntity) {


                    if (trainingDifficultProblemsPaperEntity.getTKQue() != null) {
                        view.hideLoading();
                        view.loadPaperData(trainingDifficultProblemsPaperEntity);
                    }else {
                        view.showNoData("暂无内容");
                    }
                }


            @Override
            public void onError(Throwable e) {
                super.onError(e);
                view.showNetError();
            }

            @Override
            public void onComplete() {
                super.onComplete();
                Log.d("TML","end: "+System.currentTimeMillis());
            }
        };

        TrainingDifficultProblemsPaperApi api = new TrainingDifficultProblemsPaperApi(httpOnNextListener, (TrainingDifficultProblemsPaperActivity)view);

        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {
        getData(false);
    }

    @Override
    public void getDataByStatus(int position) {
        getData(false);
    }

    @Override
    public void getDataByQuesType(String quesTypeId) {
        getData(false);
    }


}